package cn.wolfcode.crm.web.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import com.github.pagehelper.PageInfo;

import cn.wolfcode.crm.domain.Customer;
import cn.wolfcode.crm.domain.FormalCustomer;
import cn.wolfcode.crm.domain.SystemDictionaryItem;
import cn.wolfcode.crm.query.CustomerQueryObject;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.query.SystemDictionaryItemQueryObject;
import cn.wolfcode.crm.service.ICustomerService;
import cn.wolfcode.crm.service.IFormalCustomerService;
import cn.wolfcode.crm.service.ISystemDictionaryItemService;
import cn.wolfcode.crm.service.impl.CustomerServiceImpl;

@Controller
@RequestMapping("/formalCustomer")
public class FormalCustomerController {
	@Autowired
	private IFormalCustomerService formalCustomerService;
	
	@Autowired
	private ISystemDictionaryItemService systemDictionaryItemService;
	
	@Autowired
	private ICustomerService customerService;

	@RequestMapping("/list")
	public String list(@ModelAttribute("qo") QueryObject qo, Model model) {
		PageInfo<FormalCustomer> pageInfo = formalCustomerService.list(qo);
		
		SystemDictionaryItemQueryObject qo1 = new SystemDictionaryItemQueryObject();
		qo1.setParentId(4L);	//课程
		List<SystemDictionaryItem> curriculums = systemDictionaryItemService.listNotPage(qo1);
		CustomerQueryObject qo2 = new CustomerQueryObject();
		qo2.setStatus(-1);
		//查询所有客户
		List<Customer> customers = customerService.listNotPage(qo2);
		
		model.addAttribute("curriculums", curriculums);
		model.addAttribute("customers", customers);
		model.addAttribute("pageInfo", pageInfo);
		return "formalCustomer/list";
	}

	@RequestMapping("/saveOrUpdate")
	public String saveOrUpdate(FormalCustomer entity) {
		formalCustomerService.saveOrUpdate(entity);
		return "redirect:/formalCustomer/list.do";
	}
}
